package com.digoyo.hr.controller.system.basic;

import com.digoyo.hr.model.Position;
import com.digoyo.hr.model.RespBean;
import com.digoyo.hr.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Daniel
 * @Description:
 * @Date: Created in 11:32 AM 2020/5/29
 * @Modified By:
 */


@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    @Autowired
    PositionService positionService;
    @GetMapping("/")
    public List<Position> getAllPositions(){
       return  positionService.getAllPositions();
    }

    @PostMapping("/")
    public RespBean addPositon(@RequestBody Position position){
        if (positionService.addPosition(position)==1) {
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @PutMapping("/")
    public RespBean updatePositon(@RequestBody Position position){
        if (positionService.updatePosition(position)==1) {
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
    @DeleteMapping("/{id}")
    public RespBean deletePositionById(@PathVariable Integer id){
        if (positionService.deletePositionById(id) == 1) {
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @DeleteMapping("/")
    public RespBean deletePositionByIds(Integer[] ids){
        if (positionService.deletePositionByIds(ids) == ids.length) {
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
}
